<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>商品详情</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script src="/static/js/js/jquery.min.js"></script>
    <link rel="stylesheet" href="/static/js/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="/static/js/bootstrap/css/bootstrap-theme.css">
    <script src="/static/js/jquery-validation/jquery.validate.min.js"></script>
    <script src="/static/js/jquery-validation/localization/messages_zh.min.js"></script>
    <script src="/static/js/js/common.js"></script>
    <script src="/static/js/js/md5.min.js"></script>
    <script src="/static/js/layer/layer.js"></script>
</head>
<body>

<div class="panel panel-default">
  <div class="panel-heading">秒杀商品详情</div>
  <div class="panel-body">
  	<span th:if="${user eq null}"> 您还没有登录，请登陆后再操作<br/></span>
  	<span>没有收货地址的提示。。。</span>
  </div>
  <table class="table" id="goodslist">
  	<tr>  
        <td>商品名称</td>  
        <td colspan="3" th:text="${goods.goodsName}"></td> 
     </tr>  
     <tr>  
        <td>商品图片</td>  
        <td colspan="3"><img th:src="@{${goods.goodsImg}}" width="200" height="200" /></td>  
     </tr>
     <tr>  
        <td>秒杀开始时间</td>  
        <td th:text="${#dates.format(goods.startTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
        <td id="miaoshaTip">	
        	<input type="hidden" id="remainSeconds" th:value="${remainSeconds}" />
        	<span th:if="${miaoshaStatus eq 0}">秒杀倒计时：<span id="countDown" style="font-size: 18px;color:red" th:text="${remainSeconds}"></span>秒</span>
        	<span th:if="${miaoshaStatus eq 1}">秒杀进行中</span>
        	<span th:if="${miaoshaStatus eq 2}">秒杀已结束</span>
        </td>
        <td>
        	<form id="miaoshaForm" method="post" action="/seckill/seckillgoods/do_miaosha">
        		<button class="btn btn-primary btn-block" type="submit" id="buyButton">立即秒杀</button>
        		<input type="hidden" name="goodsId" th:value="${goods.goodsId}" />
        	</form>
        </td>
     </tr>
     <tr>  
        
        <td>商品原价</td>  
        <td colspan="3" th:text="${goods.goodsPrice}"></td>
     </tr>
      <tr>  
        <td>秒杀价</td>  
        <td colspan="3" th:text="${goods.goodsEndPrice}"></td>
     </tr>
     <tr>  
        <td>库存数量</td>  
        <td colspan="3" th:text="${goods.goodsStock}"></td>
     </tr>
  </table>
</div>
</body>
<script>


$(function(){
	//页面加载立刻执行的js代码
	countDown();
});

function countDown(){
	
	 var remainSeconds = $("#remainSeconds").val();
	 var timeout;
	 if(remainSeconds>0){ //秒杀未开始 
		 $("#buyButton").attr("disabled",true);
	 
		 timeout = setTimeout(function (){
	    	 $("#remainSeconds").val(remainSeconds-1);   
	    	 $("#countDown").html(remainSeconds-1);      
	    	 countDown();
	     },1000);
		 
	 }else if(remainSeconds==0){//秒杀正在进行
		 $("#miaoshaTip").html(" 秒杀正在进行");
		 $("#buyButton").attr("disabled",false);
		 if(setTimeout){
			clearTimeout(timeout); 
		 }
	 }else{ //秒杀结束
		 $("#miaoshaTip").html(" 秒杀结束");
		 $("#buyButton").attr("disabled",true);
	 }
	 
}


















 /* $(function (){
	 countDown();
 });
 
 function countDown(){
	 //1首先获取秒杀的剩余时间
	 //2 判断秒杀是否开始，结束 还是正在进行
	 //2.1 如果秒杀没有开始，我们需要做什么？
	 //2.2 如果已经开始，我们需要做什么？
	 //2.3 如果秒杀结束，我们需要做什么？
	 var remainSeconds = $("#remainSeconds").val();
	     var timeout;
	 if(remainSeconds>0){ //没有开始    秒杀倒计时
		 //秒杀按钮不能点击 
		 $("#buyButton").attr("disabled",true);
	 
	     //每隔一秒更新一下时间显示  
	     timeout= setTimeout(function(){
		 //显示剩余时间
		 $("#countDown").text(remainSeconds-1);  //显示的值减少1
		 $("#remainSeconds").val(remainSeconds-1);         //对象的值减少1 
	    	 //回调  
	    	 countDown();
	     },1000); 
	 }else if(remainSeconds==0){  //秒杀正在进行  
		 //秒杀按钮能能点击 
		 $("#buyButton").attr("disabled",false);
	     $("#miaoshaTip").html("秒杀正在进行中...");
	     //取消上面的定时任务
	     if(timeout){
	        clearTimeout(timeout); 
	     }
	 }else {  
		 //秒杀按钮能不能点击 
		 $("#buyButton").attr("disabled",true); 
	     $("#miaoshaTip").html("秒杀已经结束");
	 }
	 
	 
 } */


 
</script>
</html>
